<template>
	<my-main title="客户询价" isBack :table="table" @search="getTbody" @infoFun="infoFun">
		<template #tableTbody="{ tbody }">
			<my-list :options="tbody">
				<template #item="{ row }">
					<view class="p-16 bg-color-white radius-8">
						<view class="flex-between-center">
							<view class="f-32 fwb">{{ row.ClientName }}</view>
						</view>
						<view class="f-24 text-color-text m-t-12">{{ `客户名称 ：${row.ClientName || '--'}` }}</view>
						<view class="f-24 text-color-text m-t-12">{{ `询价备注 ：${row.InquiryDesc || '--'}` }}</view>
						<view class="m-t-12">
							<my-good type="priceLog" :row="row.ProdDesc"></my-good>
						</view>
						<view class="flex-between-center m-t-12 f-24 text-color-text">
							<text>{{ `创建人：${row.OperName || ''}` }}</text>
							<text>{{ `创建时间：${row.CrtTime || ''}` }}</text>
						</view>
					</view>
				</template>
			</my-list>
		</template>
		<template #footer>
			<view class="m-16">
				<my-button @click="addBtn">开始询价</my-button>
			</view>
		</template>
	</my-main>
	<SelectCustomer v-model="isShow" @click="seletcCustomer"></SelectCustomer>
</template>

<script lang="uts" setup>
	import SelectCustomer from "@/pages/select/SelectCustomer/SelectCustomer.vue"
//公共状态
import { useVue  } from '@/utils/useVue.uts'
const { reactive, ref,app,Token,onMounted,watch,http,goToPage,formatDate,getTimeAgo,proxy } = useVue()
const scanResult=ref('')
// 表单数据
const formData:any = reactive({
})
const options=reactive({
})
const isShow=ref(false)
// 表单数据
const table:any = reactive({
	loading: false,//数据加载
	search:{
		PageLimit: 10,
		PageIndex: 1,
		Count: 0,
		ClientName: "",
		BeginDate:getTimeAgo(3,'month'),
		EndDate:formatDate(),
	},
	searchSet:{
		searchKey:'ClientName',
		searchLabel:'用户名称',
	},
	tbody:[],
})
//搜索
const addBtn = () => {
	isShow.value=true
}
//搜索
const seletcCustomer = (row:any) => {
	isShow.value=false
	goToPage('/order/priceLog/details',{
		ClientCode:row.ClientCode,
		ClientName:row.ClientName,
	})
}
//搜索
const getTbody = (scrollSet?:any) => {
	table.loading=true
	http.request({
		url: 'api/WareHouse/GetFinInquiryRecHis',
		data: table.search,
		isNotToken: true,
		success: (res : any) => {
			const _arr = res.List.map((el:any)=>{
				const good=JSON.parse(el.ProdDesc)
				return {
					...el,
					ProdDesc:{
						ProdNickName: el.ProdName,
						...good,
						Parts:good.parts.map((part:any)=>({
							...part,
							PaperNum:part.PagesNum,
							SigOrDbl:part.PrtSigOrDbl,
							Color:part.PrtColor,
							PrtAfts:part.AttrWithNum.map((prtAfts:any)=>({
								PrtAftAttrName:prtAfts.PrtAttrName
							})),
						})),
					},
				}
			})
			table.tbody.push(..._arr)
			table.search.Count = res.Count
			if(table.summary?.length>0){
				table.summary.forEach((el:any)=>{
					el.value=res[el.prop]
				})
			}
			_scrollSet()
		},
		fail:()=>{
			_scrollSet()
		}
	})
	function _scrollSet(){
		table.loading=false
		if(scrollSet){
			scrollSet.triggered=false
		}
	}
}
//初始运行
const infoFun = () => {
	getTbody()
}
onMounted(() => {

})
</script>

<style scoped lang="scss">
.class-name {
	font-weight: bold;
}
</style>
